package org.credo.thread;

public class Thread_Daemon extends Thread{

	public static void main(String[] args) {
		Thread_Daemon daemonThread=new Thread_Daemon();
		daemonThread.setDaemon(true);
		daemonThread.start();
		//注意上面的,setDaemon(true)必须在start之前,否则报错.threadStateException.
		for(int i=0;i<10;i++){
			System.out.println(Thread.currentThread().getName()+" "+i);
		}
	}
	
	public void run(){
		for(int i=0;i<10000;i++){
			System.out.println(getName()+" "+i);
		}
	}
	//可以发现run方法并不会循环1W次,因此,守护线程在前台线程全挂了之后也跟着挂了.
}
